package com.linkoog.devtools.code_generator.setting.configurable.ui.template.dialog;

import com.linkoog.devtools.code_generator.Bundle;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.ui.ValidationInfo;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.uiDesigner.core.GridConstraints;
import com.intellij.uiDesigner.core.GridLayoutManager;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
import java.awt.*;

public class TemplateRootDialog extends DialogWrapper {

    private JPanel myMainPanel;
    private JTextField nameField;
    private JLabel nameLabel;


    public TemplateRootDialog(JComponent jComponent, String title, String text) {
        super(jComponent, false);
        if (title != null) {
            setTitle(title);
        }

        if (!StringUtil.isEmptyOrSpaces(text)) {
            nameField.setText(text);
        }

        setModal(true);
        setResizable(false);
        setSize(75, 35);
        init();
    }

    @Nullable
    @Override
    protected ValidationInfo doValidate() {
        ValidationInfo info = null;
        if (StringUtil.isEmptyOrSpaces(nameField.getText())) {
            info = new ValidationInfo(Bundle.message("validate.template.add.name"));
        }
        return info;
    }

    public String getInputText() {
        return nameField.getText();
    }

    @Override
    protected @Nullable JComponent createCenterPanel() {
        return myMainPanel;
    }


    {
// GUI initializer generated by IntelliJ IDEA GUI Designer
// >>> IMPORTANT!! <<<
// DO NOT EDIT OR ADD ANY CODE HERE!
        $$$setupUI$$$();
    }

    /**
     * Method generated by IntelliJ IDEA GUI Designer
     * >>> IMPORTANT!! <<<
     * DO NOT edit this method OR call it in your code!
     *
     * @noinspection ALL
     */
    private void $$$setupUI$$$() {
        myMainPanel = new JPanel();
        myMainPanel.setLayout(new GridLayoutManager(1, 2, new Insets(10, 10, 10, 10), -1, -1));
        nameField = new JTextField();
        myMainPanel.add(nameField, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false));
        nameLabel = new JLabel();
        nameLabel.setText("Template Name");
        myMainPanel.add(nameLabel, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
        nameLabel.setLabelFor(nameField);
    }

    /**
     * @noinspection ALL
     */
    public JComponent $$$getRootComponent$$$() {
        return myMainPanel;
    }
}
